<template>
  <div class="app-container">

    <el-row>
      <el-card>
        <el-tabs v-model="activeTab">
          <el-tab-pane
            label="撰写病例"
            name="activity"
          >
            <activity
              :user="user"
              @showDialogUser="showDialogUser"
            />
          </el-tab-pane>
          <el-tab-pane
            label="诊断记录"
            name="timeline"
          >
            <timeline />
          </el-tab-pane>
          <!-- <el-tab-pane
            label="用药记录"
            name="account"
          >
            <account :user="user" />
          </el-tab-pane> -->
        </el-tabs>
      </el-card>
      <el-col
        :span="24"
        :xs="24"
      />
    </el-row>

    <el-dialog
      class="select-medicine-dialog"
      :visible.sync="dialogUser"
      :title="'选择用户'"
      width="80%"
      :show-close="false"
      :close-on-click-modal="false"
      append-to-body
    >
      <user @confirm="selectUser" @handleCancel="cancelUser" />
    </el-dialog>
  </div>
</template>

<script>
import Activity from './components/Activity'
import Timeline from './components/Timeline'
import Account from './components/Account'
import user from '@/components/user'
import { addPrescription } from '@/api/prescription'

export default {
  name: 'Profile',
  components: { Activity, Timeline, Account, user },
  data() {
    return {
      user: {},
      activeTab: 'activity',
      dialogUser: false,
      userId: ''
    }
  },
  computed: {
  },
  created() {
  },
  methods: {
    showDialogUser() {
      this.dialogUser = true
    },
    selectUser(data) {
      if (data.id) {
        addPrescription({ userId: data.id, medicationTimeStart: Date.parse(new Date()),
          medicationTimeEnd: Date.parse(new Date()) }).then(res => {
          this.$router.push({
            name: 'prescriptionDetail',
            params: {
              prescriptionId: res.data
            }
          })
        })
      } else {
        this.$message({
          message: '需要选个人开始写'
        }
        )
      }
    },
    cancelUser(){
      this.$router.go(-1)
    }
  }
}

</script>
